package com.service.calculate.hookArmCase;

import com.service.bean.data.Data;
import com.service.bean.device.HookArmCase;
import com.service.bean.point.Point;
import com.service.bean.signal.GpsHookArmCaseSignal;
import com.service.cache.CacheManager;
import com.service.other.Coordinate;
import com.service.other.Logger;
import com.service.socket.protocol.DataProtocol;

/**
 * 解析勾臂车箱体GPS定位数据
 * @author lj
 *
 */
public class HookArmCaseSignalCreator {
	/**
	 * 勾臂车箱体
	 */
	private HookArmCase box;
	/**
	 * 定位数据
	 */
	private GpsHookArmCaseSignal signal;
	/**
	 * 协议数据区
	 */
	private Data data;
	/**
	 * 基础信息解析
	 */
	private HookArmCaseBasalCalculator basalCal = null;
	/**
	 * 状态信息解析
	 */
	private HookArmCaseStatusCalculator statusCal = null;
	
	public HookArmCaseSignalCreator(String dataArea, String deviceNo) {
		box = CacheManager.instance().getHookArmCase(deviceNo);
		// 不同的协议版本对应不同的处理方法
		data = DataProtocol.Parser(dataArea, box.device.version);
		signal = new GpsHookArmCaseSignal();
		signal.gpsNo = deviceNo;
		signal.caseId = box.caseId;
		signal.caseName = box.caseName;
		signal.companyCode = box.company.code;
		basalCal = new HookArmCaseBasalCalculator();
		statusCal = new HookArmCaseStatusCalculator();
	}
	
	public GpsHookArmCaseSignal createSignal() {
		try {
			basalCal.calculate(data, signal);
			statusCal.calculate(data, signal);
			calculateCoordinate();
		} catch (Exception e) {
			Logger.err(e);
		}
		return signal;
	}
	
	/**
	 * gps坐标转百度坐标
	 */
	private void calculateCoordinate(){
		Point p = new Point(signal.lat,signal.lng);
		p = Coordinate.gpsToWgs84(p);
		p = Coordinate.wgs84ToBd09(p);
		signal.baiduLat = p.baiduLat;
		signal.baiduLng = p.baiduLng;
	}
	
}
